package com.day08_Set_test;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @ClassName: TreeSet_demo2
 * @Author: 豆豆在睡觉
 * @Create 2024/3/8-22:41
 * @Version 1.0
 */
public class TreeSet_demo2 {
    public static void main(String[] args) {
        TreeSet<Student> trs = new TreeSet<Student>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int age = o1.getAge() - o2.getAge();
                return age == 0 ? o1.getName().compareTo(o2.getName()) : age;

            }
        });
        Student s1 = new Student("zw", 31);
        Student s2 = new Student("zwa", 31);
        Student s3 = new Student("azw", 33);
        Student s4 = new Student("bzw", 34);
        Student s5 = new Student("nzw", 36);
        trs.add(s1);
        trs.add(s2);
        trs.add(s3);
        trs.add(s4);
        trs.add(s5);
        for (Student s: trs) {
            System.out.println(s.getName() + "---"+s.getAge());
        }
    }
}
